package com.xie.dome.searchservice.service.impl;

import com.xie.dome.searchservice.config.DatabaseContextHolder;
import com.xie.dome.searchservice.service.DataBaseService;
import com.xie.dome.searchservice.util.DataBaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 数据库业务层接口实现类
 *
 * @author xie
 */
@Service
public class DataBaseServiceImpl implements DataBaseService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Map<String, Object>> findConfigValueList() {
        // 查询基础库
        DatabaseContextHolder.setDataBaseKey(DataBaseUtil.DB_BASIC);

        // 查询数据库配置
        String sql = "select * from T_DATABASE_CONFIG";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }

    @Override
    public List<Map<String, Object>> findConfigValue(String showName) {
        // 查询基础库
        DatabaseContextHolder.setDataBaseKey(DataBaseUtil.DB_BASIC);

        // 查询数据库配置
        String sql = "select * from T_DATABASE_CONFIG where show_name = ?";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, showName);
        return list;
    }
}
